<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form"  :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="客服账号">
              <el-input v-model="form.username" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客服角色">
              <el-select v-model="form.roleId" placeholder="请选择">
                <el-option v-for="item in roleList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预约单时间" width="236">
              <el-date-picker
                v-model="yydates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="补贴单时间" width="236">
              <el-date-picker
                v-model="btdates"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
              <!-- <el-button type="primary">导出</el-button> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <!-- table列表 -->
      <el-table :data="tableData" style="width: 100%">
        <el-table-column fixed prop="appointOrderSn" label="预约单号" />
        <el-table-column prop="applySn" label="补贴单号" />
        <el-table-column prop="allowanceMoney" label="补贴金额" />
        <el-table-column label="客服信息">
          <template slot-scope="scope">
            <div>
              <p>姓名：{{ scope.row.sellAdminName }}</p>
              <p>账号：{{ scope.row.sellAdminUserName }}</p>
              <p>角色：{{ scope.row.sellAdminRoleName }}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="username" label="报单姓名" />
        <el-table-column prop="userPhone" label="报单手机号" >
            <template slot-scope="scope">
            <div>{{scope.row.userPhone | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="serviceName" label="推荐人姓名" />
        <el-table-column prop="servicePhone" label="推荐人手机号" >
          <template slot-scope="scope">
            <div>{{scope.row.servicePhone | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="referee" label="项目信息">
          <template slot-scope="scope">
            <div>
              <p>医院：{{ scope.row.hospitalName }}</p>
              <p>项目：{{ scope.row.projectName }}</p>
              <p>价格：{{ scope.row.projectPrice }}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="applyStatus" label="补贴单状态" />
        <el-table-column  label="创建时间" >
            <template slot-scope="scope">
            <div>
              <p>预约单创建时间：{{ scope.row.orderTimeStr }}</p>
              <p>补贴单创建时间：{{ scope.row.applyTimeStr }}</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="listForm.pageNum"
            :page-sizes="page_sizes"
            :page-size="listForm.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { customerServicesFOIndexList } from '@/api/financialOther'
export default {
  name: 'CustomerServicesFOIndex',
  filters: {},
  data() {
    return {
      tableLoading: true,
      yydates: [],
      btdates: [],
      form: {
        username: '',
        roleId: null,
        orderBeginTime: '',
        orderEndTime: '',
        applyBeginTime: '',
        applyEndTime: '',
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      listForm: {
        pageNum: 1,
        pageSize: 10
      },
      roleList: [
        { id: null, name: '全部' },
        { id: 1, name: '超级管理员' },
        { id: 2, name: '电销主管理员' },
        { id: 3, name: '网咨主管理员' },
        { id: 4, name: '电销子账号' },
        { id: 5, name: '网咨子账号' }
      ]
    }
  },
  mounted() {
    this.getList(this.listForm)
  },
  methods: {
    // 成功状态弹窗
    succStatus(txt) {
      this.$message({
        message: txt + '成功',
        type: 'success'
      })
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.$message.error(txt + '失败')
    },
    // 列表数据获取
    getList(e) {
      this.tableLoading = true
      const datas = e
      customerServicesFOIndexList(datas)
        .then(res => {
          // console.log(res)
          if (!res.data.code) {
            // console.log(res)
            this.tableData = res.data.data.list
            this.page_totals = res.data.data.count
            if (this.tableData.length > 0) {
              this.tableData.forEach(item => {
                if (item.applyStatus == 0) {
                  item.applyStatus = '未审核 '
                } else if (item.applyStatus == 1) {
                  item.applyStatus = '通过 '
                } else if (item.applyStatus == 2) {
                  item.applyStatus = '不通过 '
                } else if (item.applyStatus == 3) {
                  item.applyStatus = '初审 '
                } else if (item.applyStatus == 4) {
                  item.applyStatus = '客户合作协议未签名 '
                }
              })
            }
          } else {
            this.$message.error(res.data.msg)
          }
          this.tableLoading = false
        })
        .catch(error => {
          this.$message.error(error)
        })
    },
    // 查询
    searchFn() {
      this.form.pageNum = 1
      if (this.yydates != null) {
        if (this.yydates.length) {
          this.form.orderBeginTime = this.yydates[0]
          this.form.orderEndTime = this.yydates[1]
        }
      } else {
        this.form.orderBeginTime = ''
        this.form.orderEndTime = ''
      }
      if (this.btdates != null) {
        if (this.btdates.length) {
          this.form.applyBeginTime = this.btdates[0]
          this.form.applyEndTime = this.btdates[1]
        }
      } else {
        this.form.applyBeginTime = ''
        this.form.applyEndTime = ''
      }
      this.getList(this.form)
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.pageSize = val
      this.getList(this.form)
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.pageNum = val
      this.getList(this.form)
    }
  }
}
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>
